package br.com.usjt.locadoraweb.bean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import br.com.usjt.locadoraweb.model.Vehicle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;


@ManagedBean(name="consultVehicleBean")
@SessionScoped
public class ConsultVehicleBean {
	

	private Vehicle vehicleSelected;
	private Vehicle vehicle;
	private List<Vehicle> vehicles;
	
	public ConsultVehicleBean(){
		vehicle = new Vehicle();
	}
	
	
	public List<Vehicle> getVehicles() {
		return vehicles;
	}

	public void setVehicles(List<Vehicle> vehicles) {
		this.vehicles = vehicles;
	}

	public Vehicle getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	public Vehicle getVehicleSelected() {
		System.out.println("VEICULO SELECIONADO " + vehicleSelected);
		return vehicleSelected;
	}
	
	public void setVehicleSelected(Vehicle vehicleSelected) {
		System.out.println("VEICULO ESCOLHIDO " + vehicleSelected);
		this.vehicleSelected = vehicleSelected;
	}



	public void includeVehicle(){
		try {  
	        FacesContext.getCurrentInstance().getExternalContext().redirect("Vehicle.jsf"); // <--- AQUI  
	    } catch (IOException ex) {  
	        Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE, null, ex);  
	    }  
	}
	
	public void search() throws Exception{
		Vehicle vehicle = new Vehicle();
		vehicles = new ArrayList<Vehicle>();
		vehicles = vehicle.search();
	}
}
